#################################
#								#
#   Provide Coefficient Plots   #
#                               #
#################################


rm(list=ls()) 

library(foreign)
library(arm)
library(splines)

# create a vector to store the variable names
  
  var.names <- c("Systemic Instability","","","Regional Systemic Instability","","","", "% GP Civil Wars","","","GP Inflationary Crises","","","", "Regional GP Wars","","", "% GP Wars","","","","GP War Termination","","","Regional GP War Termination","","","", "Number of New Dyads", "","","Number of Secessions","","","","Number of Proxy Wars","","","GP Alliance Shifts","","","","Composite Instability Measure","","","Regional Composite Instability")
var.names<-rev(var.names)



### Note that the values below are manually entered ###


# set the graphical parameters
par(
  family = "serif",  
  oma = c(0,0,0,0),  
  mar = c(5,10,4,2)  
  )

# create an empty plot for total customization
plot(NULL,                              # create empty plot
  xlim = c(0, 0.12),                      # set xlim by guessing
  ylim = c(.7, length(var.names) + .3), # set ylim by the number of variables
  axes = F, xlab = NA, ylab = NA)       # turn off axes and labels

# add the data
estL <- c(.0082963,"","",.0109595,"","","",.0061137,"","",.0063665,"","","",.0069801,"","",.0042948,"","","",.0093855,"","",.0103334,"","","",.0074653,"","",.0103294,"","","", .0118643,"","",.0110454, "","","",.005283,"","",.0091354) 
estH <- c(.0664841,"","",.0758866,"","","",.0425504,"","",.0518228,"","","",.0716383,"","",.0422499,"","","",.0187926,"","",.0431135,"","","",.0741086,"","",.0572429,"","","",.0402839,"","",.0280901, "","","",.0862635,"","",.0855439) 


estL<-rev(estL)
estH <-rev(estH)


# conveniently store the estimates (minus the constant)
est_lL <- c(.0054764,"","",.0098352,"","","",.0021424,"","",.0020793,"","","",.0038716,"","",.0019644,"","","",.0071989,"","",.0080862,"","","",.0052973,"","",.0090527,"","","",.0111744,"","",.0099724, "","","",.0021643,"","",.007279)
est_lH <- c(.0330041,"","",.0377469,"","","",.0265681,"","",.0258966,"","","",.0432704,"","",.0294945,"","","",.0149841,"","",.0210669,"","","",.0492759,"","",.0344394,"","","",.0203873,"","",.0188365, "","","",.0558578,"","",.0499233)

est_lL <-rev(est_lL)

est_lH <-rev(est_lH)

est_hL <- c(.0111162,"","",.0120837,"","","",.0100849,"","",.0106536,"","","",.0100886,"","",.0066252,"","","", .0115721, "","",.0125806,"","","",.0096334,"","",.011606,"","","",.0125541,"","",.0121185, "","","",.0084018,"","",.0109918)
est_hH <- c(.0999641,"","",.1140264,"","","",.0585326,"","",.077749,"","","",.1000063,"","",.0550052,"","", "", .0226011,"","",.0651601,"","","",.0989414,"","",.0800464,"","","",.0601806,"","",.0373437, "","","",.1166693,"","",.1211644)

est_hL <-rev(est_hL)                                       

est_hH <-rev(est_hH)                                       


for (i in 1:length(estL)) {                                            # loop over a counter the length of the estimate vector
  points(estL[i], i, pch = 19, cex = .5,lwd=4)                               # add the points to the plot
  points(estH[i], i, pch = 19, cex = .5,lwd=4)                               # add the points to the plot
#  lines(c(est_lL[i],est_hL[i]) , c(i, i) ,lwd=3,col="blue")        # add the 95% confidence intervals
#   lines(c(est_lH[i],est_hH[i]) , c(i, i) ,lwd=3,col="red")        # add the 95% confidence intervals
 lines(c(est_lL[i],est_hL[i]) , c(i, i) ,lwd=3,col="blue")        # add the 95% confidence intervals
   lines(c(est_lH[i],est_hH[i]) , c(i, i) ,lwd=3,col="red")        # add the 95% confidence intervals
 text(-0.02, i, var.names[i], xpd = T, cex = .8)                      # add the variable names
}

# add axes and labels
axis(side = 1)                                                                                          # add bottom axis
abline(v = 0, lty = 3, col = "grey",lwd=3)                                                                    # add verticle line
mtext(side = 1, "(Blue Interval median values; Red Intervals 95th percentile values)", line = 3)                                              # label bottom axis
mtext(side = 3, "Substantive Effect of Systemic Instability Variables", line = 1)   # add title
box()                                







